ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
LIN_UART.h File Reference

Drivers for serial link (SCI/UART/LIN) More...

#include "derivative.h"

Go to the source code of this file.

Data Structures

union  LINUARTConfig_t

Defines

#define TRUE   (1u)
#define CLEAR   (0u)
#define BITS_IN_NIBBLE   (4u)
#define BITS_IN_BYTE   (8u)
#define BITS_IN_32   (32u)
#define BITS_IN_16   (16u)
#define BYTES_IN_32   (4u)
#define BYTES_IN_16   (2u)
#define BIT_DEFINITION
#define BIT0   (1u << 0u)
#define BIT1   (1u << 1u)
#define BIT2   (1u << 2u)
#define BIT3   (1u << 3u)
#define BIT4   (1u << 4u)
#define BIT5   (1u << 5u)
#define BIT6   (1u << 6u)
#define BIT7   (1u << 7u)
#define BIT8   (1u << 8u)
#define BIT9   (1u << 9u)
#define BIT10   (1u << 10)
#define BIT11   (1u << 11)
#define BIT12   (1u << 12)
#define BIT13   (1u << 13)
#define BIT14   (1u << 14)
#define BIT15   (1u << 15)
#define BIT16   (1u << 16)
#define BIT17   (1u << 17)
#define BIT18   (1u << 18)
#define BIT19   (1u << 19)
#define BIT20   (1u << 20)
#define BIT21   (1u << 21)
#define BIT22   (1u << 22)
#define BIT23   (1u << 23)
#define BIT24   (1u << 24)
#define BIT25   (1u << 25)
#define BIT26   (1u << 26)
#define BIT27   (1u << 27)
#define BIT28   (1u << 28)
#define BIT29   (1u << 29)
#define BIT30   (1u << 30)
#define BIT31   (1u << 31)
#define N_LIN_INSTANCES   (2u)
#define UART_PHYSICAL_BUFF_SIZE   (4u)
#define SCI_TIME_OUT   (0x00040000u)
#define LIN_UART_ENABLED   (0x80000000u)
#define LIN_UART_DISABLED   (0x00000000u)
#define LIN_TX_BUFF_1_BYTES   (0x00000000u)
#define LIN_TX_BUFF_2_BYTES   (0x20000000u)
#define LIN_TX_BUFF_3_BYTES   (0x40000000u)
#define LIN_TX_BUFF_4_BYTES   (0x60000000u)
#define LIN_RX_BUFF_1_BYTES   (0x00000000u)
#define LIN_RX_BUFF_2_BYTES   (0x08000000u)
#define LIN_RX_BUFF_3_BYTES   (0x10000000u)
#define LIN_RX_BUFF_4_BYTES   (0x18000000u)
#define LIN_NO_PARITY_CHECK   (0x00000000u)
#define LIN_ODD_PARITY_CHECK   (0x06000000u)
#define LIN_EVEN_PARITY_CHECK   (0x02000000u)
#define LIN_7_BIT_WORD_SIZE   (0x00000000u)
#define LIN_8_BIT_WORD_SIZE   (0x01000000u)
#define UART_NO_DATA_RX   ((uint8_t)BIT7)
#define UART_INVALID_BUFFER_SIZE   ((uint8_t)BIT2)
#define UART_TIMEOUT   ((uint8_t)BIT1)
#define UART_NOT_READY   ((uint8_t)BIT0)
#define LIN_MANTISSA(xx)   (xx << 8u)
#define LIN_FRACTION(xx)   (xx << 20u)

Typedefs

typedef struct LINFLEX_tagLINFLEX_t

Enumerations

enum  LIN_STATE_MACHINE_STATES {
  LIN_ASLEEP = 0, LIN_INIT, LIN_IDLE, LIN_BREAK,
  LIN_BREAK_DELIMITER, LIN_SYNCH_FIELD, LIN_ID_FIELD, LIN_HEADER_DONE,
  LIN_DATA_TX_RX, LIN_CHECKSUM
}
enum  LIN_INSTANCES_LIST { LIN_INSTANCE_0 = 0, LIN_INSTANCE_1, LIN_INSTANCE_2, LIN_INSTANCE_3 }
enum  LIN_UART_BUFFER_REGISTERS { UART_BUFF0 = 0u, UART_BUFF1, UART_BUFF2, UART_BUFF3 }

Functions

uint8_t u8fnUARTWrite (const uint8_t u8Instance, const uint8_t *pu8UARTTx, const uint8_t u8Size)
 This function will write n number of bytes to the UART. If this operation is not successful after some time, the routine will time-out. It will wait inside the function until all data has been transmitted.
uint8_t u8fnUARTRead (const uint8_t u8Instance, const uint8_t *pu8UARTRx, const uint8_t u8Size)
 This function will read n number of bytes from the UART and place them in an array before exiting. If the number is not achieved, the routine will time-out eventually.
uint8_t u8fnLINUARTSend (const uint8_t u8Instance, const uint8_t *pu8UARTTx, const uint8_t u8Size)
 This function will start writing data through the UART. The remaining data will be sent eventually through interrupts. It will NOT wait for all data to be sent before exiting.
uint8_t u8fnLINUARTReceive (const uint8_t u8Instance, const uint8_t *pu8UARTRx, const uint8_t u8IsrEn)
 This function will enable data to be received via a UART, and will allow data to keep flowing in indefinitely. This function will NOT wait for data to be ready before it exits.
uint8_t u8fnConfigLINUARTGeneral (const LINUARTConfig_t *tLINUARTConfig)
 This function will configure a particular instance of the LIN peripheral for use as a UART/SCI.
uint8_t u8fnLINUARTGetDataNoIsr (uint8_t u8Instance)
 Gathers data from the buffer without using Isrs.
uint8_t u8fnWaitForUARTTxBufferToEmpty (uint8_t u8Instance, uint32_t u32TimeOut)
 This function will wait for the Interrupts Enable bit to turn off or time-out while doing so. The purpose of such routine is to make sure not to start a new buffer transmission while there's one ongoing.
void vfnEnableLINRxISR (uint8_t u8Instance, uint8_t u8Switch)
 This internal function will enable or disable Reception interrupts.
void vfnEnableLINTxISR (uint8_t u8Instance, uint8_t u8Switch)
 This internal function will enable or disable transmission interrupts.
void vfnLIN0TxIsr (void)
 Interrupt Service routine for data transmission of Instance 0. This routine will call vfnGenericLINTxIsr.
void vfnLIN1TxIsr (void)
 Interrupt Service routine for data transmission of Instance 1. This routine will call vfnGenericLINTxIsr.
void vfnLIN2TxIsr (void)
 Interrupt Service routine for data transmission of Instance 2. This routine will call vfnGenericLINTxIsr.
void vfnLIN3TxIsr (void)
 Interrupt Service routine for data transmission of Instance 3. This routine will call vfnGenericLINTxIsr.
void vfnLIN0RxIsr (void)
 Interrupt Service routine for data reception of Instance 0. This routine will call vfnGenericLINTxIsr.
void vfnLIN1RxIsr (void)
 Interrupt Service routine for data reception of Instance 1. This routine will call vfnGenericLINTxIsr.
void vfnLIN2RxIsr (void)
 Interrupt Service routine for data reception of Instance 2. This routine will call vfnGenericLINTxIsr.
void vfnLIN3RxIsr (void)
 Interrupt Service routine for data reception of Instance 3. This routine will call vfnGenericLINTxIsr.

Variables

vuint8_t gau8LINUARTWordsTx [N_LIN_INSTANCES]
vuint8_t gau8LINUARTWordsRx [N_LIN_INSTANCES]
vuint8_t gau8LINUARTRxFlagHasBeenClearedByTx [N_LIN_INSTANCES]
vuint8_t * gpu8LINUARTTxBuffer [N_LIN_INSTANCES]
vuint8_t * gpu8LINUARTRxBuffer [N_LIN_INSTANCES]

Detailed Description

Drivers for serial link (SCI/UART/LIN)

Copyright (c) 2011 Freescale Semiconductor Freescale Confidential Proprietary

Author:
Freescale Semiconductor
SASD Automotive
R11515
Version:
Date:
Warning:
(If needed)

History:


Define Documentation

#define N_LIN_INSTANCES   (2u)

This limit is given by HW


Function Documentation

uint8_t u8fnConfigLINUARTGeneral ( const LINUARTConfig_t tLINUARTConfig)

This function will configure a particular instance of the LIN peripheral for use as a UART/SCI.

Parameters:
LINUARTConfig_t,:pointer to a 32-bit word with relevant configuration. Refer to LINUARTConfig_t for more info.
Returns:
CLEAR if executed correctly; State-machine state in which the HW is stuck (as defined by LIN_STATE_MACHINE_STATES) otherwise.
uint8_t u8fnLINUARTGetDataNoIsr ( uint8_t  u8Instance)

Gathers data from the buffer without using Isrs.

Parameters:
u8Instance,:Value determining the LIN instance to read from.
Returns:
UART_NO_DATA_RX if no data is in the buffer; UART_INVALID_BUFFER_SIZE in case configuration for the buffer size is incorrect (should never happen); CLEAR if data has been gathered successfully.
uint8_t u8fnLINUARTReceive ( const uint8_t  u8Instance,
const uint8_t *  pu8UARTRx,
const uint8_t  u8IsrEn 
)

This function will enable data to be received via a UART, and will allow data to keep flowing in indefinitely. This function will NOT wait for data to be ready before it exits.

Parameters:
u8Instance,:Value determining the LIN instance from which data should be read.
pu8UARTRx,:Pointer to RAM location where incoming data should be placed.
u8IsrEn,:TRUE if Rx interrupts shall be used, CLEAR otherwise.
Returns:
UART_NOT_READY in case HW is in config mode and the operation couldn't thake place; CLEAR otherwise.
uint8_t u8fnLINUARTSend ( const uint8_t  u8Instance,
const uint8_t *  pu8UARTTx,
const uint8_t  u8Size 
)

This function will start writing data through the UART. The remaining data will be sent eventually through interrupts. It will NOT wait for all data to be sent before exiting.

Parameters:
u8Instance,:Value determining the LIN instance from which data should be read.
pu8UARTTx,:Pointer to data to transmit.
u8Size,:Amount of bytes to write.
Returns:
Clear if no problems find; UART_NOT_READY if HW or SW are not ready or busy with a previous Tx, or if HW state-machine does not change states as requested; UART_INVALID_BUFFER_SIZE if buffer size is not in agreement with HW settings;
uint8_t u8fnUARTRead ( const uint8_t  u8Instance,
const uint8_t *  pu8UARTRx,
const uint8_t  u8Size 
)

This function will read n number of bytes from the UART and place them in an array before exiting. If the number is not achieved, the routine will time-out eventually.

Parameters:
u8Instance,:Value determining the LIN instance from which data should be read.
pu8UARTRx,:Pointer to RAM location where incoming data should be placed.
u8Size,:Amount of bytes to be read.
Returns:
UART_NOT_READY in case HW is in config mode and the operation couldn't thake place; UART_TIMEOUT if we have timed-out without receiving all expected data; CLEAR otherwise.
uint8_t u8fnUARTWrite ( const uint8_t  u8Instance,
const uint8_t *  pu8UARTTx,
const uint8_t  u8Size 
)

This function will write n number of bytes to the UART. If this operation is not successful after some time, the routine will time-out. It will wait inside the function until all data has been transmitted.

Parameters:
u8Instance,:Value determining the LIN instance from which data should be read.
pu8UARTTx,:Pointer to data to transmit.
u8Size,:Amount of bytes to write.
Returns:
Clear if no problems find; UART_NOT_READY if HW or SW are not ready or busy with a previous Tx, or if HW state-machine does not change states as requested; UART_INVALID_BUFFER_SIZE if buffer size is not in agreement with HW settings; UART_TIMEOUT if we have timed-out without sending all data.
uint8_t u8fnWaitForUARTTxBufferToEmpty ( uint8_t  u8Instance,
uint32_t  u32TimeOut 
)

This function will wait for the Interrupts Enable bit to turn off or time-out while doing so. The purpose of such routine is to make sure not to start a new buffer transmission while there's one ongoing.

Parameters:
u8Instance,:Value determining the LIN instance to write to.
u32TimeOut,:Value to use as time-out. This value is decremented in a while loop. If it expires, an error flag UART_TIMEOUT is set.
Returns:
Clear if no problems find, UART_TIMEOUT if we have timed-out.
void vfnEnableLINRxISR ( uint8_t  u8Instance,
uint8_t  u8Switch 
)

This internal function will enable or disable Reception interrupts.

Parameters:
u8Instance,:Instance of the LIN module to operate on.
u8Switch,:Non-zero to enable, zero to disable.
Returns:
void.
Note:
This function should not be called by the user.
void vfnEnableLINTxISR ( uint8_t  u8Instance,
uint8_t  u8Switch 
)

This internal function will enable or disable transmission interrupts.

Parameters:
u8Instance,:Instance of the LIN module to operate on.
u8Switch,:Non-zero to enable, zero to disable.
Returns:
void.
void vfnLIN0RxIsr ( void  )

Interrupt Service routine for data reception of Instance 0. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN0TxIsr ( void  )

Interrupt Service routine for data transmission of Instance 0. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN1RxIsr ( void  )

Interrupt Service routine for data reception of Instance 1. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN1TxIsr ( void  )

Interrupt Service routine for data transmission of Instance 1. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN2RxIsr ( void  )

Interrupt Service routine for data reception of Instance 2. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN2TxIsr ( void  )

Interrupt Service routine for data transmission of Instance 2. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN3RxIsr ( void  )

Interrupt Service routine for data reception of Instance 3. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.
void vfnLIN3TxIsr ( void  )

Interrupt Service routine for data transmission of Instance 3. This routine will call vfnGenericLINTxIsr.

Parameters:
void.
Returns:
void.

Variable Documentation

vuint8_t gau8LINUARTRxFlagHasBeenClearedByTx[N_LIN_INSTANCES]

SW flag that is set when there is pending Rx data but the HW flag has been cleared by the Tx Done HW action.

vuint8_t gau8LINUARTWordsRx[N_LIN_INSTANCES]

Number of words that have been received per instance

vuint8_t gau8LINUARTWordsTx[N_LIN_INSTANCES]

Number of words to be transmitted per instance

vuint8_t* gpu8LINUARTRxBuffer[N_LIN_INSTANCES]

Rx Global for 8-bit transfers

vuint8_t* gpu8LINUARTTxBuffer[N_LIN_INSTANCES]

Tx Global for 8-bit transfers